var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../@babel/runtime/helpers/defineProperty")),
  e = require("../../services/api.js"),
  a = require("../../utils/util.js"),
  url = require("../../services/baseURL.js");

getApp();

Page((0, t.default)({
  data: {
    navAtive: 0,
    homeBanner: [1, 2, 3],
    lists: [],
    types: [],
    count: 0,
    page: 1,
    tjStores: [],
    tjGoods: [],
    show_task: !0,
    show_shop: !0
  },
  onLoad: function(t) {
    this.getStoreTypes(), t.referrer && wx.setStorageSync("referrer_id", t.referrer);
  },
  goSearch: function() {
    wx.navigateTo({
      url: "/pages/search/index"
    });
  },
  getStoreTypes: function() {
    var t = this;
    wx.request({
      url: "".concat(url.baseURL, "/xcxapi/category"),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(e) {
        if (200 === e.data.status) {
          t.setData(t.setData({
            types: e.data.data
          }), wx.setStorageSync("store-type", e.data.data));
        }
      },
      fail(res) {
        console.log("请求错误！");
      }
    })
    // var t = this;
    // (0, e.getStoreType)().then(function(e) {
    //     200 === e.data.code && (t.setData({
    //         types: e.data.data
    //     }), wx.setStorageSync("store-type", e.data.data));
    // });
  },
  tabChange: function(t) {
    this.setData({
      navAtive: t.currentTarget.dataset.id
    });
  },
  goProducts: function() {
    wx.navigateTo({
      url: "/pages/products/index"
    });
  },
  onShareAppMessage: function() {},
  goTask: function() {
    wx.navigateTo({
      url: "/pages/task/index"
    });
  },
  onShow: function() {
    var t = this;
    (0, a.getLocation)() ? this.getStores(): wx.getLocation({
      success: function(e) {
        var o = e.latitude,
          n = e.longitude;
        console.log(o)
        console.log(e), (0, a.setLocation)({
          name: "成都",
          latitude: o,
          longitude: n
        }), t.getStores();
      },
      fail: function(e) {
        console.log(e), t.getStores();
      }
    }), this.getTjStores(), this.getTjGoods();
  },
  getTjStores: function() {
    var t = this;
    // (0, e.getTaskLists)({
    //     page: 1,
    //     pageSize: 4,
    //     hao_dian: 1
    // }).then(function(e) {
    //     200 === e.data.code && t.setData({
    //         tjStores: e.data.data.list,
    //         show_task: e.data.data.list.length > 0
    //     });
    // });
    wx.request({
      url: "".concat(url.baseURL, "/xcxapi/recommend"),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(e) {
        if (200 === e.data.status) {
          t.setData(t.setData({
            tjStores: e.data.data,
            show_task: e.data.data.length > 0
          }));
        }
      },
      fail(res) {
        console.log("请求错误！");
      }
    });
  },
  getTjGoods: function() {
    var t = this;
    // (0, e.getTaskLists)({
    //   page: 1,
    //   pageSize: 4,
    //   da_pai: 1
    // }).then(function(e) {
    //   if (200 === e.data.code) {
    //     var a = e.data.data.list.map(function(t) {
    //       return t.yh = Math.floor(t.ot_price - t.price), t;
    //     });
    //     t.setData({
    //       tjGoods: a,
    //       show_shop: a.length > 0
    //     });
    //   }
    // });
    wx.request({
      url: "".concat(url.baseURL, "/xcxapi/recommend"),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(e) {
        if (200 === e.data.status) {
          var a = e.data.data;
          t.setData({
            tjGoods: a,
            show_shop: a.length>0
          });
        }
      },
      fail(res) {
        console.log("请求错误！");
      }
    });
  },
  getStores: function() {
    var t = this,
      o = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1,
      n = (0,
        a.getLocation)();
    // (0, e.getTaskLists)({
    //   lng: n.longitude,
    //   lat: n.latitude,
    //   pageSize: 8,
    //   page: o
    // }).then(function(e) {
    //   if (200 === e.data.code) {
    //     var a = e.data.data.list.map(function(t) {
    //       return t.money = parseInt(t.money), t.isend = parseInt(t.last_total_task) <= 0,
    //         t;
    //     });
    //     t.setData({
    //       lists: o > 1 ? [].concat(t.data.lists, a) : a,
    //       count: e.data.data.count,
    //       page: o
    //     });
    //   }
    // });
    wx.request({
      url: "".concat(url.baseURL, "/xcxapi/goodslist"),
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(e) {
        if (200 === e.data.status) {
          t.setData({
            lists: e.data.data[0],
            count: e.data.data.count,
            page: e.data.data.pagesize,
          });
        }
      },
      fail(res) {
        console.log("请求错误！");
      }
    });
  },
  onReachBottom: function() {
    var t = this.selectComponent("#pagination");
    if (!t) return !1;
    var e = t.hasMore();
    e && this.getStores(e);
  },
  onPullDownRefresh: function() {
    wx.stopPullDownRefresh(), this.onShow();
  }
}, "onShareAppMessage", function() {
  return {
    path: "/pages/index/index",
    imageUrl: "/images/shareo.jpg",
    title: "免费的外卖才更”香“"
  };
}));